package com.bvgole.examples.rocket.producer.controller;/**
 * @Classname BeforeInit
 * @Description TODO
 * @Date 2021/4/29 16:10
 * @Created by GUOCHEN
 */

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @program: my-spring-completely
 * @description:
 * @author: GUOCHEN
 * @create: 2021/04/29 16:10
 */
//@Component
public class BeforeInit implements InitializingBean {
    @Autowired
    DefaultMQProducer defaultMQProducer;

    public static final Logger LOGGER = LoggerFactory.getLogger(BeforeInit.class);

    @Override
    public void afterPropertiesSet() throws Exception {
        Message sendMsg = new Message("TestTopic", "TestTag", "hello rocket MQ".getBytes());
        // 默认3秒超时
        SendResult sendResult = defaultMQProducer.send(sendMsg);
        LOGGER.info("消息发送响应：" + sendResult.toString());
    }
}
